<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Vue:组件动态切换</title>
		<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="app">
			<button @click="changeComp(1)">组件一</button><button @click="changeComp(2)">组件二</button><button @click="changeComp(3)">组件二</button>
			<keep-alive>
				<component v-bind:is="nowHeader"></component>
			</keep-alive>
		</div>
		<script type="text/javascript">
			new Vue({
				el: '#app',
				data: {
					nowHeader: 'my-header1'
				},
				components:{
					'my-header1': {
						template: '<p>组件一：<input /></p>'
					},
					'my-header2': {
						template: '<p>组件二：<input /></p>'
					},
					'my-header3': {
						template: '<p>组件三：<input /></p>'
					}
				},
				methods:{
					changeComp: function (index) {
						this.nowHeader = 'my-header' + index;
					}
				}
			});
		</script>
	</body>
</html>
